WPS Office.apk(点击下载) / zmu.java


package defpackage;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import com.baidu.tts.loopj.AsyncHttpResponseHandler;
import com.mopub.mobileads.VastExtensionXmlManager;
import defpackage.zmv;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/* renamed from: zmu  reason: default package */
public class zmu {
    private static zmu BdE = null;
    private static zmt BdF = null;
    private static final String BdG = zna.TAG;
    private static boolean BdH = false;
    private static zne BdI;
    public Context mContext = null;

    private zmu(Context context) {
        this.mContext = context;
    }

    private static long cQ(Context context, String str) {
        return PreferenceManager.getDefaultSharedPreferences(context).getLong(str, 0);
    }

    private JSONArray gOl() {
        JSONArray jSONArray = new JSONArray();
        try {
            JSONArray gOm = gOm();
            for (int i = 0; i < gOm.length(); i++) {
                jSONArray.put(gOm.getJSONObject(i));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        try {
            JSONArray gOn = gOn();
            for (int i2 = 0; i2 < gOn.length(); i2++) {
                jSONArray.put(gOn.getJSONObject(i2));
            }
        } catch (JSONException e2) {
            e2.printStackTrace();
        }
        for (JSONObject jSONObject : gOp()) {
            jSONArray.put(jSONObject);
        }
        for (JSONObject jSONObject2 : gOo()) {
            jSONArray.put(jSONObject2);
        }
        return jSONArray;
    }

    private static JSONArray gOm() {
        JSONArray jSONArray = new JSONArray();
        try {
            if (BdI == null) {
                return jSONArray;
            }
            List<String> gOA = BdI.gOA();
            if (gOA.size() > 0) {
                for (String str : gOA) {
                    JSONObject jSONObject = new JSONObject();
                    jSONObject.put(VastExtensionXmlManager.TYPE, zmv.a.COUNT_EVENT.value);
                    jSONObject.put("account", str);
                    for (String str2 : BdI.afa(str)) {
                        List<String> ik = BdI.ik(str, str2);
                        JSONArray jSONArray2 = new JSONArray();
                        for (String str3 : ik) {
                            for (Integer num : BdI.br(str, str2, str3)) {
                                int intValue = num.intValue();
                                JSONObject jSONObject2 = new JSONObject();
                                jSONObject2.put(str3, intValue);
                                jSONArray2.put(jSONObject2);
                            }
                        }
                        jSONObject.put(znh.afd(str2), jSONArray2);
                    }
                    jSONArray.put(jSONObject);
                }
            }
            return jSONArray;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static JSONArray gOn() {
        JSONArray jSONArray = new JSONArray();
        if (BdI == null) {
            return jSONArray;
        }
        for (String str : BdI.gOz()) {
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.put(VastExtensionXmlManager.TYPE, zmv.a.FLOW_EVENT.value);
                jSONObject.put("account", str);
                List<String> aeZ = BdI.aeZ(str);
                JSONArray jSONArray2 = new JSONArray();
                for (String str2 : aeZ) {
                    zmw zmw = new zmw(str2);
                    zmw.BdR = BdI.ij(str, str2);
                    jSONArray2.put(zmw.gOr());
                }
                jSONObject.put("flow", jSONArray2);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            jSONArray.put(jSONObject);
        }
        return jSONArray;
    }

    private static List<JSONObject> gOo() {
        ArrayList arrayList = new ArrayList();
        List<zmy> gOo = BdI.gOo();
        HashMap hashMap = new HashMap();
        try {
            for (zmy zmy : gOo) {
                if (!hashMap.containsKey(zmy.dML)) {
                    hashMap.put(zmy.dML, new HashMap());
                }
                if (!((Map) hashMap.get(zmy.dML)).containsKey(zmy.wzn)) {
                    ((Map) hashMap.get(zmy.dML)).put(zmy.wzn, new HashMap());
                }
                if (!((Map) ((Map) hashMap.get(zmy.dML)).get(zmy.wzn)).containsKey(Long.valueOf(zmy.BdV))) {
                    ((Map) ((Map) hashMap.get(zmy.dML)).get(zmy.wzn)).put(Long.valueOf(zmy.BdV), new JSONArray());
                }
                ((JSONArray) ((Map) ((Map) hashMap.get(zmy.dML)).get(zmy.wzn)).get(Long.valueOf(zmy.BdV))).put(new JSONObject(zmy.BdU));
            }
            for (Map.Entry entry : hashMap.entrySet()) {
                JSONObject jSONObject = new JSONObject();
                jSONObject.put(VastExtensionXmlManager.TYPE, zmv.a.NEW_CUSTOM_EVENT.value);
                jSONObject.put("account", entry.getKey());
                if (((Map) entry.getValue()).size() != 0) {
                    JSONObject jSONObject2 = new JSONObject();
                    for (Map.Entry entry2 : ((Map) entry.getValue()).entrySet()) {
                        if (((Map) entry2.getValue()).size() != 0) {
                            JSONObject jSONObject3 = new JSONObject();
                            for (Map.Entry entry3 : ((Map) entry2.getValue()).entrySet()) {
                                if (((JSONArray) entry3.getValue()).length() != 0) {
                                    jSONObject3.put(((Long) entry3.getKey()).toString(), entry3.getValue());
                                }
                            }
                            jSONObject2.put((String) entry2.getKey(), jSONObject3);
                        }
                    }
                    jSONObject.put("payload", jSONObject2);
                    arrayList.add(jSONObject);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return arrayList;
    }

    private static List<JSONObject> gOp() {
        JSONObject gOj;
        ArrayList arrayList = new ArrayList();
        if (zna.Bed != null) {
            try {
                znm.b(zna.TAG, "Use client defined custom event", new Object[0]);
                for (zmr zmr : zna.Bed) {
                    if (!(zmr == null || (gOj = zmr.gOj()) == null || gOj.length() <= 0)) {
                        String gOi = zmr.gOi();
                        if (gOi == null) {
                            gOi = "";
                        }
                        JSONObject jSONObject = new JSONObject();
                        jSONObject.put(VastExtensionXmlManager.TYPE, zmv.a.CUSTOM_EVENT.value);
                        jSONObject.put("account", gOi);
                        jSONObject.put("payload", gOj);
                        arrayList.add(jSONObject);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return arrayList;
    }

    private boolean gOq() {
        int i;
        HttpEntity httpEntity;
        if (BdI == null) {
            return false;
        }
        if (BdI == null) {
            i = 1;
        } else {
            List<zmx> gOw = BdI.gOw();
            BdF.BcU = gOw;
            i = gOw.size() == 0 ? 1 : 0;
        }
        zmt zmt = BdF;
        Context context = this.mContext;
        zmt.BcY = i;
        znf kW = znf.kW(context);
        if (kW != null) {
            String gOI = znf.gOI();
            if (TextUtils.isEmpty(gOI)) {
                gOI = "127.0.0.1";
            }
            zmt.BcK = gOI;
            zmt.BcO = kW.gON();
        } else {
            znm.d(znm.aXE(), "Get device info instance failed", new Object[0]);
        }
        zmt.BcM = Long.valueOf(System.currentTimeMillis());
        zmt.jaX = znh.afc(zmt.BcR + zmt.BcS + zmt.BcM + "icibaclient_#&$%");
        BdF.BcV = gOl();
        BdF.BcT = znd.kU(this.mContext);
        try {
            String zmt2 = BdF.toString();
            if (znn.kX(this.mContext)) {
                znm.b(zna.TAG, "The upload data is: " + zmt2, new Object[0]);
            }
            ArrayList arrayList = new ArrayList();
            arrayList.add(new BasicNameValuePair("q", zmt2));
            httpEntity = new UrlEncodedFormEntity(arrayList, AsyncHttpResponseHandler.DEFAULT_CHARSET);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            httpEntity = null;
        } catch (Throwable th) {
            th.printStackTrace();
            BdH = true;
            return true;
        }
        znl gOR = znl.gOR();
        String str = "https://counter.kingsoft.com:443/index2.php";
        if (znn.kX(this.mContext)) {
            str = "https://apollo.kingsoft.com/index2.php";
        }
        return gOR.a(str, httpEntity);
    }

    public static zmu kP(Context context) {
        if (BdE == null) {
            synchronized (zmu.class) {
                if (BdE == null) {
                    if (context != null) {
                        BdF = new zmt(context.getApplicationContext());
                        BdI = zne.kV(context.getApplicationContext());
                        BdE = new zmu(context.getApplicationContext());
                    } else {
                        znm.d(BdG, "Failed to init KSODataUtil because of the null context", new Object[0]);
                    }
                }
            }
        }
        return BdE;
    }

    public static long kQ(Context context) {
        long abs = Math.abs(System.currentTimeMillis() - cQ(context, "KSODataLastUploadTime"));
        long j = 5000;
        if (znn.kX(context)) {
            j = 30000;
        } else if (abs < 28800000) {
            j = 28800000 - abs;
        }
        znm.b(zna.TAG, "Next upload time is " + (j / 3600000) + "H " + ((j % 3600000) / 60000) + "M " + ((j % 60000) / 1000) + "S later", new Object[0]);
        return j;
    }

    public static boolean kR(Context context) {
        return znh.eo(System.currentTimeMillis()) > cQ(context, "KSOBaseDataLastUploadTime");
    }

    public final boolean KT(boolean z) {
        return (z || znn.kX(this.mContext)) ? gOk() : z;
    }

    public final synchronized boolean gOk() {
        boolean gOq;
        BdI.gOE();
        znm.b(BdG, "Start to upload data...", new Object[0]);
        gOq = gOq();
        if (gOq) {
            BdI.gOD();
            znm.b(zna.TAG, "Upload data success, delete them.", new Object[0]);
            BdI.gOC();
            if (zna.Bed != null) {
                Iterator<zmr> it = zna.Bed.iterator();
                while (it.hasNext()) {
                    it.next();
                }
            }
            SharedPreferences.Editor edit = PreferenceManager.getDefaultSharedPreferences(this.mContext).edit();
            long currentTimeMillis = System.currentTimeMillis();
            edit.putLong("KSOBaseDataLastUploadTime", znh.eo(currentTimeMillis));
            edit.putLong("KSODataLastUploadTime", currentTimeMillis);
            edit.commit();
            if (BdH) {
                zna.ii("wpsmail_uploadData_OutOfMemory", "");
                BdH = false;
            }
        } else {
            BdI.gOE();
            znm.d(BdG, "Error: Upload mail data failed", new Object[0]);
        }
        return gOq;
    }
}